package com.situ.blog.service.impl;

import com.situ.blog.dao.IBlogDao;
import com.situ.blog.dao.impl.BlogDaoImpl;
import com.situ.blog.pojo.entity.Blog;
import com.situ.blog.pojo.query.BlogQuery;
import com.situ.blog.pojo.vo.BlogVo;
import com.situ.blog.service.IBlogService;
import com.situ.blog.util.PageInfo;

import java.util.List;

public class BlogServiceImpl implements IBlogService {
    private IBlogDao blogDao = new BlogDaoImpl();
    @Override
    public PageInfo selectByPage(BlogQuery blogQuery) {
        List<BlogVo> list = blogDao.selectByPage(blogQuery);
        int totalCount = blogDao.selectTotalCount(blogQuery);
        System.out.println(list);
        return PageInfo.ok(totalCount, list);
    }

    @Override
    public void add(Blog blog) {
        blogDao.add(blog);
    }

    @Override
    public void deleteById(Integer id) {
        blogDao.deleteById(id);
    }

    @Override
    public void deleteAll(String[] ids) {
        for (String id : ids) {
            blogDao.deleteById(Integer.parseInt(id));
        }
    }

    @Override
    public Blog selectById(Integer id) {
        return blogDao.selectById(id);
    }

    @Override
    public void update(Blog blog) {
        blogDao.update(blog);
    }

    @Override
    public void updateStatus(Integer id, Integer status) {
        blogDao.updateStatus(id, status);
    }
}
